package DEV_FF;

import java.util.concurrent.TimeUnit;
import org.junit.*;

import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;


	public class c_Regisration_DEV {
	  private static WebDriver driver;
	  private static StringBuffer verificationErrors = new StringBuffer();

	  @BeforeClass
	  public static void setUp() throws Exception {
	    driver = new FirefoxDriver();
	    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	  }

	  @Test
	  public void Registration_ru_Dev() throws Exception {
	    goToMainPage_ru();
	    registrationPage("taka+03021@whotrades.org", "kalinka_03021");
	  }

	//@Test
	  public void Registration_en_Dev() throws Exception {
	    goToMainPage_en();
	    registrationPage("taka+02026@whotrades.org", "kalinka_260166");
	  }
	  
	//@Test
	  public void Registration2_ru_Dev() throws Exception {
		goToSitesPage_ru();
	    goToRegPage();
	    registrationPage2("Kalinka", "Malinka", "taka+03022@whotrades.org", "kalinka");
	  }

	@Test
	  public void Registration2_en_Dev() throws Exception {
		goToSitesPage_en();  
	    goToRegPage();
	    registrationPage2("Kalinka", "Malinka", "taka+03022@whotrades.org", "kalinka");
	  }

	//@Test
	  public void Registration_mma_Dev() throws Exception {
		goToRegPage_mma();
	    registrationPage3("Kalinka", "Malinka", "taka+02029@whotrades.org", "kalinka", "71111111111");
	  }
	
	//@Test
	  public void Registration_forex_Dev() throws Exception {
		goToRegPage_forex();
	    registrationPage3("Kalinka", "Malinka", "taka+02024@whotrades.org", "kalinka", "71111111111");
	  }
			
	private void registrationPage(String user_name, String user_email) {
		user_email(user_name);
	    user_name(user_email);
	    user_agreement();
	    send_form();
	}
	
	private void registrationPage2 (String user_name,  String user_lastname, String user_email, String user_password) {
		  user_name(user_name);
		  user_lastname(user_lastname);
		  user_email(user_email);
		  user_pass(user_password);
		  user_pass2(user_password);
		  user_agreement();
		  send_form();
	}

	private void registrationPage3 (String user_name,  String user_lastname, String user_email, String user_password, String user_phone) {
		  user_name(user_name);
		  user_lastname(user_lastname);
		  user_email(user_email);
		  user_pass(user_password);
		  user_pass2(user_password);
		  reg_user_phone(user_phone);
		  user_agreement();
		  send_form();
	}

	private void reg_user_phone(String user_phone) {
		driver.findElement(By.id("reg_user_phone")).clear();
		driver.findElement(By.id("reg_user_phone")).sendKeys(user_phone);
	}
	
	private void send_form() {
		driver.findElement(By.id("send_form")).click();
	    driver.findElement(By.cssSelector("input.text-link-style")).click();
	}

	private void user_agreement() {
		driver.findElement(By.id("reg-user-agreement")).click();
	    driver.findElement(By.id("reg-user-agreement")).click();
	}

	private void user_email(String user_name) {
		driver.findElement(By.id("reg_user_email")).clear();
	    driver.findElement(By.id("reg_user_email")).sendKeys(user_name);
	}

	private void user_name(String user_email) {
		driver.findElement(By.id("reg_user_name")).clear();
	    driver.findElement(By.id("reg_user_name")).sendKeys(user_email);
	}
	
	
	private void user_pass2(String user_password) {
		driver.findElement(By.id("reg_user_password2")).clear();
		driver.findElement(By.id("reg_user_password2")).sendKeys(user_password);
	}

	private void user_pass(String user_password) {
		driver.findElement(By.id("reg_user_password")).clear();
		driver.findElement(By.id("reg_user_password")).sendKeys(user_password);
	}

	private void user_lastname(String user_lastname) {
		driver.findElement(By.id("reg_user_lastname")).clear();
		driver.findElement(By.id("reg_user_lastname")).sendKeys(user_lastname);
	}

	  
	private void goToRegPage_mma() {
		driver.get("https://whotrades.dev.whotrades.net/go/mma-demo?iframe=1&popup=1&getHandlerWidgetId=GroupsItemregistrationRegistration&backurl=http://whotrades.dev.whotrades.net/go/mma-demo");
		}
	
	private void goToRegPage_forex() {
		driver.get("https://whotrades.dev.whotrades.net/go/forex-demo?iframe=1&popup=1&getHandlerWidgetId=GroupsItemregistrationRegistration&backurl=http://whotrades.dev.whotrades.net/go/forex-demo");
		}
	
	private void goToRegPage() {
		driver.findElement(By.xpath("//header[@id='header']/div[3]/nav/div/a[2]/span")).click();
	}
	
	private void goToSitesPage_en() {
		driver.get("http://whotrades.dev.whotrades.net/en/sites");
	}
	  
	private void goToSitesPage_ru() {
		driver.get("http://whotrades.dev.whotrades.net/ru/sites");
		
	}
	  
	 private void goToMainPage_en() {
		 driver.get("http://whotrades.dev.whotrades.net/en");
	}
	  
	  private void goToMainPage_ru() {
		  driver.get("http://whotrades.dev.whotrades.net/ru");
	}
	  
	  @AfterClass
	  public static void tearDown() throws Exception {
	    String verificationErrorString = verificationErrors.toString();
	    if (!"".equals(verificationErrorString)) {
	      fail(verificationErrorString);
	    }
	  }

	
	}

	